package com.heaton.videocar

import android.app.Application
import android.content.Context
import androidx.annotation.NonNull
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.ViewModelStore
import com.heaton.baselib.CoreBase
import com.heaton.videocar.core.ActivityHookCallback
import com.heaton.videocar.core.AppLifeObserver
import com.heaton.videocar.core.BleManager
import com.heaton.videocar.core.SocketManager


/**
 * author: jerry
 * date: 20-11-26
 * email: superliu0911@gmail.com
 * des:
 */
class App: Application() {

    companion object{
        lateinit var instace: App
        lateinit var context: Context
        var appViewModelStore: ViewModelStore?=null
    }

    override fun onCreate() {
        super.onCreate()
        instace = this
        context = applicationContext
        CoreBase.init(this)
        ProcessLifecycleOwner.get().lifecycle.addObserver(AppLifeObserver())
        BleManager.get().init(this)
        //FpsViewer.getViewer().initViewer(this)
        registerActivityLifecycleCallbacks(ActivityHookCallback())
        SocketManager.initSocket()
    }

    //定义全局的ViewModelStore
    @NonNull
    fun getViewModelStore(): ViewModelStore {
        if (appViewModelStore == null) {
            appViewModelStore = ViewModelStore()
        }
        return appViewModelStore!!
    }


}